package com.zjsru.oneDay202205;

/**
 * @Author: likew
 * @Date: 2022/5/9
 * 增减字符串匹配
 * 如果perm[i] < perm[i + 1]，那么s[i] == 'I'
 * 如果perm[i] > perm[i + 1]，那么 s[i] == 'D'
 *
 * 输入：s = "IDID"
 * 输出：[0,4,1,3,2]
 *
 * 输入：s = "III"
 * 输出：[0,1,2,3]
 */
public class diStringMatch {
    public int[] diStringMatch(String s) {
       int len = s.length(), l = 0, r = len, idx =0;
       int[] ans = new int[len + 1];
        for (int i = 0; i < len; i++) {
            ans[idx++] = s.charAt(i) == 'I' ? l++ : r--;
        }
        ans[idx] = 1;
        return ans;
    }
    
    public static void main(String[] args) {
        diStringMatch diStringMatch = new diStringMatch();
        String s = "DDI";
        System.out.println(diStringMatch.diStringMatch(s));
    }
}
